﻿#region << 文 件 说 明 >>

/*----------------------------------------------------------------
// 文件名称：SreachControl
// 创 建 者：杨程
// 创建时间：2021/12/21 10:26:27
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//
//
//----------------------------------------------------------------*/

#endregion

namespace Vampirewal.Core.WPF.Theme;

public class SearchControl : TextBox
{
    private ResourceDictionary res
    {
        get
        {
            return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core.WPF.Theme;component/Theme.xaml", UriKind.RelativeOrAbsolute) };
        }
    }

    public SearchControl()
    {
        //构造函数

        var BaseStyle = res["SearchControlStyle"] as Style;

        this.Style = BaseStyle;
    }

    private TextBox SearchText { get; set; }
    private Button SearchButton { get; set; }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        SearchText = this.Template.FindName("SearchText", this) as TextBox;

        if (SearchTextStyle != null)
        {
            SearchText.Style = SearchTextStyle;
        }

        SearchButton = this.Template.FindName("SearchButton", this) as Button;

        if (SearchButtonStyle != null)
        {
            SearchButton.Style = SearchButtonStyle;
        }
    }



    #region 依赖属性

    public ICommand SearchCommand
    {
        get { return (ICommand)GetValue(SearchCommandProperty); }
        set { SetValue(SearchCommandProperty, value); }
    }

    // Using a DependencyProperty as the backing store for SreachCommand.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SearchCommandProperty =
        DependencyProperty.Register("SearchCommand", typeof(ICommand), typeof(SearchControl), new PropertyMetadata(null));

    public Style SearchTextStyle
    {
        get { return (Style)GetValue(SearchTextStyleProperty); }
        set { SetValue(SearchTextStyleProperty, value); }
    }

    // Using a DependencyProperty as the backing store for SreachTextStyle.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SearchTextStyleProperty =
        DependencyProperty.Register("SearchTextStyle", typeof(Style), typeof(SearchControl), new PropertyMetadata(null));

    public Style SearchButtonStyle
    {
        get { return (Style)GetValue(SearchButtonStyleProperty); }
        set { SetValue(SearchButtonStyleProperty, value); }
    }

    // Using a DependencyProperty as the backing store for SearchButtonStyle.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SearchButtonStyleProperty =
        DependencyProperty.Register("SearchButtonStyle", typeof(Style), typeof(SearchControl), new PropertyMetadata(null));

    #endregion
}